package com.cps116.friendstracker;

/**
 * This is the generic Activity class that all the other classes extend.
 * There are menu option-related code and shared preference code.
 */

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class BaseActivity extends Activity implements OnSharedPreferenceChangeListener{

	private SharedPreferences prefs;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//set up the shared application preferences..
        prefs = PreferenceManager.getDefaultSharedPreferences(this); 
        prefs.registerOnSharedPreferenceChangeListener(this);   
        	
	}

	
	
	//create the option menu 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.friendstracker_menu, menu);
		return true;
	}

	//switching between different views
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {                              // 
		case R.id.menuOptionProfile:
			startActivity(new Intent(this, ProfileActivity.class));  // 
			break;
		case R.id.menuOptionMap:
			startActivity(new Intent(this, MapActivity.class));
			break;
		case R.id.menuOptionQuery:
			startActivity(new Intent(this, QueryActivity.class));
			break;
		case R.id.menuOptionToggle:
			break;
		}
		
		return true;  // 
	}

	
	
	public void onSharedPreferenceChanged(SharedPreferences preferences, String string) {
		//be able to update the user's preference
			
	}
	
	
	
	
	
	
	
}
